From: Keir Fraser Date: Wed, 8 Jul 2009 21:08:31 +0000 (+0100) Subject: Replace boot-time free-pages bitmap with a region list. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13627 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=0409e29e2bd9ff5e30cb0bfe5ba49b7aed19ae5e;p=xen.git Replace boot-time free-pages bitmap with a region list. Signed-off-by: Keir Fraser --- diff --git a/xen/arch/ia64/xen/xenmem.c b/xen/arch/ia64/xen/xenmem.c index f4ea1453c2..1c66734352 100644 --- a/xen/arch/ia64/xen/xenmem.c +++ b/xen/arch/ia64/xen/xenmem.c @@ -87,8 +87,6 @@ alloc_dir_page(void) { unsigned long mfn = alloc_boot_pages(1, 1); unsigned long dir; - if (!mfn) - panic("Not enough memory for virtual frame table!\n"); ++table_size; dir = mfn << PAGE_SHIFT; clear_page(__va(dir)); @@ -101,8 +99,6 @@ alloc_table_page(unsigned long fill) unsigned long mfn = alloc_boot_pages(1, 1); unsigned long *table; unsigned long i; - if (!mfn) - panic("Not enough memory for virtual frame table!\n"); ++table_size; table = (unsigned long *)__va((mfn << PAGE_SHIFT)); for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) @@ -245,8 +241,6 @@ void __init init_frametable(void) * address is identity mapped */ pfn = alloc_boot_pages( frame_table_size >> PAGE_SHIFT, FT_ALIGN_SIZE >> PAGE_SHIFT); - if (pfn == 0) - panic("Not enough memory for frame table.\n"); frame_table = __va(pfn << PAGE_SHIFT); memset(frame_table, 0, frame_table_size); diff --git a/xen/arch/ia64/xen/xensetup.c b/xen/arch/ia64/xen/xensetup.c index 2d17de3ce5..bde96cab0e 100644 --- a/xen/arch/ia64/xen/xensetup.c +++ b/xen/arch/ia64/xen/xensetup.c @@ -514,9 +514,7 @@ skip_move: efi_print(); xen_heap_start = memguard_init(ia64_imva(&_end)); - printk("Before xen_heap_start: %p\n", xen_heap_start); - xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start))); - printk("After xen_heap_start: %p\n", xen_heap_start); + printk("xen_heap_start: %p\n", xen_heap_start); efi_memmap_walk(filter_rsvd_memory, init_boot_pages); efi_memmap_walk(xen_count_pages, &nr_pages); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 24117a6bc2..ae40ad11c8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -199,8 +199,6 @@ void __init init_frametable(void) while (nr_pages + 4 - i < page_step) page_step >>= PAGETABLE_ORDER; mfn = alloc_boot_pages(page_step, page_step); - if ( mfn == 0 ) - panic("Not enough memory for frame table\n"); map_pages_to_xen( FRAMETABLE_VIRT_START + (i << PAGE_SHIFT), mfn, page_step, PAGE_HYPERVISOR); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index a35dda5ae2..0793a74a85 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -97,7 +97,6 @@ int early_boot = 1; cpumask_t cpu_present_map; unsigned long xen_phys_start; -unsigned long allocator_bitmap_end; #ifdef CONFIG_X86_32 /* Limits of Xen heap, used to initialise the allocator. */ @@ -764,24 +763,21 @@ void __init __start_xen(unsigned long mbi_p) EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n"); reserve_e820_ram(&boot_e820, initial_images_base, initial_images_end); - /* Initialise boot heap. */ - allocator_bitmap_end = init_boot_allocator(__pa(&_end)); #if defined(CONFIG_X86_32) - xenheap_initial_phys_start = allocator_bitmap_end; + xenheap_initial_phys_start = __pa(&_end); xenheap_phys_end = DIRECTMAP_MBYTES << 20; #else if ( !xen_phys_start ) EARLY_FAIL("Not enough memory to relocate Xen.\n"); - reserve_e820_ram(&boot_e820, __pa(&_start), allocator_bitmap_end); + reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end)); #endif /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(&boot_e820); /* - * With the boot allocator now initialised, we can walk every RAM region - * and map it in its entirety (on x86/64, at least) and notify it to the - * boot allocator. + * Walk every RAM region and map it in its entirety (on x86/64, at least) + * and notify it to the boot allocator. */ for ( i = 0; i < boot_e820.nr_map; i++ ) { @@ -1132,7 +1128,6 @@ int xen_in_range(paddr_t start, paddr_t end) if ( !xen_regions[0].s ) { extern char __init_begin[], __bss_start[]; - extern unsigned long allocator_bitmap_end; /* S3 resume code (and other real mode trampoline code) */ xen_regions[0].s = bootsym_phys(trampoline_start); @@ -1144,9 +1139,9 @@ int xen_in_range(paddr_t start, paddr_t end) xen_regions[2].s = __pa(&__per_cpu_start); xen_regions[2].e = xen_regions[2].s + (((paddr_t)last_cpu(cpu_possible_map) + 1) << PERCPU_SHIFT); - /* bss + boot allocator bitmap */ + /* bss */ xen_regions[3].s = __pa(&__bss_start); - xen_regions[3].e = allocator_bitmap_end; + xen_regions[3].e = __pa(&_end); } for ( i = 0; i < ARRAY_SIZE(xen_regions); i++ ) diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index 9709553e4f..17f6147def 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -47,7 +47,6 @@ static uint64_t sinit_base, sinit_size; #define TXTCR_HEAP_SIZE 0x0308 extern char __init_begin[], __per_cpu_start[], __bss_start[]; -extern unsigned long allocator_bitmap_end; #define SHA1_SIZE 20 typedef uint8_t sha1_hash_t[SHA1_SIZE]; @@ -299,7 +298,7 @@ void tboot_shutdown(uint32_t shutdown_type) /* * Xen regions for tboot to MAC */ - g_tboot_shared->num_mac_regions = 5; + g_tboot_shared->num_mac_regions = 4; /* S3 resume code (and other real mode trampoline code) */ g_tboot_shared->mac_regions[0].start = bootsym_phys(trampoline_start); g_tboot_shared->mac_regions[0].size = bootsym_phys(trampoline_end) - @@ -315,10 +314,6 @@ void tboot_shutdown(uint32_t shutdown_type) /* bss */ g_tboot_shared->mac_regions[3].start = (uint64_t)__pa(&__bss_start); g_tboot_shared->mac_regions[3].size = __pa(&_end) - __pa(&__bss_start); - /* boot allocator bitmap */ - g_tboot_shared->mac_regions[4].start = (uint64_t)__pa(&_end); - g_tboot_shared->mac_regions[4].size = allocator_bitmap_end - - __pa(&_end); /* * MAC domains and other Xen memory diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 06d59077d4..4fafb904a9 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -68,7 +68,6 @@ void *alloc_xen_pagetable(void) } mfn = alloc_boot_pages(1, 1); - BUG_ON(mfn == 0); return mfn_to_virt(mfn); } diff --git a/xen/common/kexec.c b/xen/common/kexec.c index aa7b5ee577..baa4a657e9 100644 --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -334,7 +334,6 @@ static void crash_save_vmcoreinfo(void) VMCOREINFO_SYMBOL(domain_list); VMCOREINFO_SYMBOL(frame_table); - VMCOREINFO_SYMBOL(alloc_bitmap); VMCOREINFO_SYMBOL(max_page); VMCOREINFO_STRUCT_SIZE(page_info); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 572b3f933e..da57c58005 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -69,117 +69,78 @@ PAGE_LIST_HEAD(page_offlined_list); /* Broken page list, protected by heap_lock. */ PAGE_LIST_HEAD(page_broken_list); -/********************* - * ALLOCATION BITMAP - * One bit per page of memory. Bit set => page is allocated. +/************************* + * BOOT-TIME ALLOCATOR */ -unsigned long *alloc_bitmap; -#define PAGES_PER_MAPWORD (sizeof(unsigned long) * 8) +static unsigned long __initdata first_valid_mfn = ~0UL; -#define allocated_in_map(_pn) \ -({ unsigned long ___pn = (_pn); \ - !!(alloc_bitmap[___pn/PAGES_PER_MAPWORD] & \ - (1UL<<(___pn&(PAGES_PER_MAPWORD-1)))); }) - -/* - * Hint regarding bitwise arithmetic in map_{alloc,free}: - * -(1<= n. - * (1<= e ) + return; + for ( i = 0; i < nr_bootmem_regions; i++ ) + if ( s < bootmem_region_list[i].e ) + break; -/************************* - * BOOT-TIME ALLOCATOR - */ + BOOT_BUG_ON((i < nr_bootmem_regions) && (e > bootmem_region_list[i].s)); + BOOT_BUG_ON(nr_bootmem_regions == + (PAGE_SIZE / sizeof(struct bootmem_region))); -static unsigned long first_valid_mfn = ~0UL; + memmove(&bootmem_region_list[i+1], &bootmem_region_list[i], + (nr_bootmem_regions - i) * sizeof(*bootmem_region_list)); + bootmem_region_list[i] = (struct bootmem_region) { s, e }; + nr_bootmem_regions++; +} -/* Initialise allocator to handle up to @max_page pages. */ -paddr_t __init init_boot_allocator(paddr_t bitmap_start) +static void __init bootmem_region_zap(unsigned long s, unsigned long e) { - unsigned long bitmap_size; - - bitmap_start = round_pgup(bitmap_start); - - /* - * Allocate space for the allocation bitmap. Include an extra longword - * of padding for possible overrun in map_alloc and map_free. - */ - bitmap_size = max_page / 8; - bitmap_size += sizeof(unsigned long); - bitmap_size = round_pgup(bitmap_size); - alloc_bitmap = (unsigned long *)maddr_to_virt(bitmap_start); - - /* All allocated by default. */ - memset(alloc_bitmap, ~0, bitmap_size); + unsigned int i; - return bitmap_start + bitmap_size; + for ( i = 0; i < nr_bootmem_regions; i++ ) + { + struct bootmem_region *r = &bootmem_region_list[i]; + if ( e <= r->s ) + break; + if ( s >= r->e ) + continue; + if ( s <= r->s ) + { + r->s = min(e, r->e); + } + else if ( e >= r->e ) + { + r->e = s; + } + else + { + unsigned long _e = r->e; + r->e = s; + bootmem_region_add(e, _e); + } + } } void __init init_boot_pages(paddr_t ps, paddr_t pe) { - unsigned long bad_spfn, bad_epfn, i; + unsigned long bad_spfn, bad_epfn; const char *p; ps = round_pgup(ps); @@ -189,7 +150,7 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) first_valid_mfn = min_t(unsigned long, ps >> PAGE_SHIFT, first_valid_mfn); - map_free(ps >> PAGE_SHIFT, (pe - ps) >> PAGE_SHIFT); + bootmem_region_add(ps >> PAGE_SHIFT, pe >> PAGE_SHIFT); /* Check new pages against the bad-page list. */ p = opt_badpage; @@ -217,32 +178,29 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) printk("Marking pages %lx through %lx as bad\n", bad_spfn, bad_epfn); - for ( i = bad_spfn; i <= bad_epfn; i++ ) - if ( (i < max_page) && !allocated_in_map(i) ) - map_alloc(i, 1); + bootmem_region_zap(bad_spfn, bad_epfn+1); } } unsigned long __init alloc_boot_pages( unsigned long nr_pfns, unsigned long pfn_align) { - unsigned long pg, i; + unsigned long pg, _e; + int i; - /* Search backwards to obtain highest available range. */ - for ( pg = (max_page - nr_pfns) & ~(pfn_align - 1); - pg >= first_valid_mfn; - pg = (pg + i - nr_pfns) & ~(pfn_align - 1) ) + for ( i = nr_bootmem_regions - 1; i >= 0; i-- ) { - for ( i = 0; i < nr_pfns; i++ ) - if ( allocated_in_map(pg+i) ) - break; - if ( i == nr_pfns ) - { - map_alloc(pg, nr_pfns); - return pg; - } + struct bootmem_region *r = &bootmem_region_list[i]; + pg = (r->e - nr_pfns) & ~(pfn_align - 1); + if ( pg < r->s ) + continue; + _e = r->e; + r->e = pg; + bootmem_region_add(pg + nr_pfns, _e); + return pg; } + BOOT_BUG_ON(1); return 0; } @@ -660,12 +618,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status) *status = 0; pg = mfn_to_page(mfn); -#if defined(__x86_64__) - /* Xen's txt mfn in x86_64 is reserved in e820 */ if ( is_xen_fixed_mfn(mfn) ) -#elif defined(__i386__) - if ( is_xen_heap_mfn(mfn) ) -#endif { *status = PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED | (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT); @@ -673,14 +626,14 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status) } /* - * N.B. xen's txt in x86_64 is marked reserved and handled already - * Also kexec range is reserved + * N.B. xen's txt in x86_64 is marked reserved and handled already. + * Also kexec range is reserved. */ - if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) ) - { + if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) ) + { *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM; return -EINVAL; - } + } spin_lock(&heap_lock); @@ -703,7 +656,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status) /* Release the reference since it will not be allocated anymore */ put_page(pg); } - else if ( old_info & PGC_xen_heap) + else if ( old_info & PGC_xen_heap ) { *status = PG_OFFLINE_XENPAGE | PG_OFFLINE_PENDING | (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT); @@ -880,31 +833,18 @@ static unsigned long avail_heap_pages( return free_pages; } -#define avail_for_domheap(mfn) !(allocated_in_map(mfn) || is_xen_heap_mfn(mfn)) void __init end_boot_allocator(void) { - unsigned long i, nr = 0; - int curr_free, next_free; + unsigned int i; /* Pages that are free now go to the domain sub-allocator. */ - if ( (curr_free = next_free = avail_for_domheap(first_valid_mfn)) ) - map_alloc(first_valid_mfn, 1); - for ( i = first_valid_mfn; i < max_page; i++ ) + for ( i = 0; i < nr_bootmem_regions; i++ ) { - curr_free = next_free; - next_free = avail_for_domheap(i+1); - if ( next_free ) - map_alloc(i+1, 1); /* prevent merging in free_heap_pages() */ - if ( curr_free ) - ++nr; - else if ( nr ) - { - init_heap_pages(mfn_to_page(i - nr), nr); - nr = 0; - } + struct bootmem_region *r = &bootmem_region_list[i]; + if ( r->s < r->e ) + init_heap_pages(mfn_to_page(r->s), r->e - r->s); } - if ( nr ) - init_heap_pages(mfn_to_page(i - nr), nr); + init_heap_pages(virt_to_page(bootmem_region_list), 1); if ( !dma_bitsize && (num_online_nodes() > 1) ) { @@ -923,7 +863,6 @@ void __init end_boot_allocator(void) printk(" DMA width %u bits", dma_bitsize); printk("\n"); } -#undef avail_for_domheap /* * Scrub all unallocated pages in all heap zones. This function is more diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index a5dfe94e5c..49297296a1 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -219,14 +219,14 @@ struct page_info unsigned long _mfn = (mfn); \ (_mfn < paddr_to_pfn(xenheap_phys_end)); \ }) +#define is_xen_fixed_mfn(mfn) is_xen_heap_mfn(mfn) #else -extern unsigned long allocator_bitmap_end; #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap) #define is_xen_heap_mfn(mfn) \ (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn))) -#define is_xen_fixed_mfn(mfn) \ - ( (mfn << PAGE_SHIFT) >= __pa(&_start) && \ - (mfn << PAGE_SHIFT) <= allocator_bitmap_end ) +#define is_xen_fixed_mfn(mfn) \ + ((((mfn) << PAGE_SHIFT) >= __pa(&_start)) && \ + (((mfn) << PAGE_SHIFT) <= __pa(&_end))) #endif #if defined(__i386__) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index d00ac0a4bb..8d35ed8645 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -37,7 +37,6 @@ struct domain; struct page_info; /* Boot-time allocator. Turns into generic allocator after bootstrap. */ -paddr_t init_boot_allocator(paddr_t bitmap_start); void init_boot_pages(paddr_t ps, paddr_t pe); unsigned long alloc_boot_pages( unsigned long nr_pfns, unsigned long pfn_align); @@ -307,9 +306,7 @@ int guest_remove_page(struct domain *d, unsigned long gmfn); #define RAM_TYPE_RESERVED 0x00000002 #define RAM_TYPE_UNUSABLE 0x00000004 #define RAM_TYPE_ACPI 0x00000008 -/* Returns TRUE if the whole page at @mfn is of the requested RAM type(s) above. */ +/* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */ int page_is_ram_type(unsigned long mfn, unsigned long mem_type); -extern unsigned long *alloc_bitmap; /* for vmcoreinfo */ - #endif /* __XEN_MM_H__ */